#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(int argc,char *argv[])
{
	unsigned short port =8080;
	char *server_ip="127.0.0.1";
	char send_buf[512]="";
	char recv_buf[512]="";
	int sockfd=0;
	int err_log=0;
	struct sockaddr_in server_addr;
	
	bzero(&server_addr,sizeof(server_addr));
	server_addr.sin_family=AF_INET;
	server_addr.sin_port=htons(port);
	inet_pton(AF_INET,server_ip,&server_addr.sin_addr);
	
	sockfd=socket(AF_INET,SOCK_STREAM,0);
	if(sockfd<0)
	{
		perror("socket");
		exit(-1);
	}
	err_log=connect(sockfd,(struct sockaddr*)&server_addr,sizeof(server_addr));
	if(err_log!=0)
	{
		perror("connect");
		close(sockfd);
		exit(-1);

	}
	while(1)
	{
	fgets(send_buf,sizeof(send_buf),stdin);
	send_buf[strlen(send_buf)-1]='\0';
	send(sockfd,send_buf,strlen(send_buf),0);
	recv(sockfd,recv_buf,sizeof(recv_buf),0);
	printf("%s\n",recv_buf);
	}
	close(sockfd);
	return 0;
}
